<CFPARAM name="pID" default="#client.chapa#">
<CFPARAM name="SLcode" default= "SL">
<CFPARAM name="VLcode" default= "VL">
<CFPARAM name="ULcode" default= "UL">
<CFPARAM name="sLVLbegBal" default="0">
<CFPARAM name="ulbegBal" default="5.5">
<CFPARAM name="sLVLcred" default="1.25">
<CFPARAM name="lvDeb" default="1.1">
<CFPARAM name="sLEarnLv" default= "0">
<CFPARAM name="sLActLv" default= "0">
<CFPARAM name="vLEarnLv" default= "0">
<CFPARAM name="vLActLv" default= "0">
<CFPARAM name="uLActLv" default= "0">
<CFPARAM name="SLActBal" default= "0">
<CFPARAM name="VLActBal" default= "0">
<CFPARAM name="ULActBal" default= "0">
<CFPARAM name="SLpend" default= "0">
<CFPARAM name="VLpend" default= "0">
<CFPARAM name="ULpend" default= "0">



<cfif IsDefined("GETENTRY.ROUTEID") AND Len(GETENTRY.ROUTEID)>
    <CFQUERY NAME="qryPID" DATASOURCE="#CLIENT.COMPANY_DSN#">    
         SELECT PERSONNELIDNO 
         FROM CINLEAVEAPPSI
         WHERE ROUTEID = '#GETENTRY.ROUTEID#'
    </cfquery>
    <cfset pID = qryPID.PERSONNELIDNO>
</cfif>

<CFQUERY name="getPA" datasource="#CLIENT.COMPANY_DSN#">
	SELECT DATEHIRED
    FROM CMFPA
    WHERE PERSONNELIDNO = '#pID#'
</CFQUERY>

<CFIF YEAR(getPA.DATEHIRED) EQ YEAR(NOW())>
	<CFSET moHired = Month(getPA.DATEHIRED)>
    <CFSET daHired = Day(getPA.DATEHIRED)>
	<CFSET nMo = (Month(Now()) - Month(getPA.DATEHIRED)) - 1>    
    <CFIF nMo>
		<CFSET sLVLbegBal = ((DaysInMonth(moHired) - daHired) * sLVLcred ) / DaysInMonth(moHired)>
        <CFSET sLVLbegBalTEMP = nMo * sLVLcred>
        <CFSET sLVLbegBal = sLVLbegBalTEMP + sLVLbegBal>
    </CFIF>
<CFELSE>
	<CFSET nMo = Month(Now())>
    <CFSET sLVLbegBal = nMo * sLVLcred>
</CFIF>

<CFIF sLVLbegBal LT ulbegBal>
	<CFSET ulbegBal = sLVLbegBal>
    <CFSET ulbegBal = NumberFormat(ulbegBal,'9.99')>
</CFIF>
<CFSET sLVLbegBal = NumberFormat(sLVLbegBal,'9.99')>

<CFQUERY NAME="getEnt" DATASOURCE="#CLIENT.COMPANY_DSN#">
	SELECT LEAVEENTITLEMENT, LEAVEBALANCE, AVAILEDLEAVE, LEAVETYPE
    FROM CINLVENTITLEMENT
    WHERE PERSONNELIDNO  = '#pID#'
    AND LEAVETYPE IN ('#SLcode#','#VLcode#','#ULcode#')
</CFQUERY>

<CFIF getEnt.RecordCount>
    <cfquery name="sl" dbtype="query">
    	SELECT * FROM getEnt
        WHERE LEAVETYPE = '#SLcode#'
    </cfquery>
    
    <CFIF sl.RecordCount>
		<CFSET sLEarnLv = sl.LEAVEENTITLEMENT>
        <CFSET sLActLv = sl.AVAILEDLEAVE>
    </CFIF>
    
    <cfquery name="vl" dbtype="query">
    	SELECT * FROM getEnt
        WHERE LEAVETYPE = '#VLcode#'
    </cfquery>
    <CFIF vl.RecordCount>
		<CFSET vLEarnLv = vl.LEAVEENTITLEMENT>
        <CFSET vLActLv = vl.AVAILEDLEAVE>
    </CFIF>
    
    
     <cfquery name="ul" dbtype="query">
    	SELECT * FROM getEnt
        WHERE LEAVETYPE = '#ULcode#'
    </cfquery>
    <CFIF ul.RecordCount>
    	<CFSET uLActLv = ul.AVAILEDLEAVE>  
    </CFIF>
</CFIF>

<CFQUERY NAME="getLvs" DATASOURCE="#CLIENT.COMPANY_DSN#">
	SELECT COUNT(DOCNUMBER) AS COUNT, LEAVETYPE
    FROM CINLEAVEAPPSI
    WHERE PERSONNELIDNO  = '#pID#'
    AND LEAVETYPE IN ('#SLcode#','#VLcode#','#ULcode#')
    AND APPROVED IS NOT NULL
    AND APPROVED NOT IN ('Y','N')
    GROUP BY LEAVETYPE
</CFQUERY>

<CFIF getLvs.RecordCount>
    <cfquery name="sl" dbtype="query">
    	SELECT * FROM getLvs
        WHERE LEAVETYPE = '#SLcode#'
    </cfquery> 
    <CFIF sl.RecordCount>
    	<cfset SLpend = sl.COUNT>
    </CFIF>
    
    <cfquery name="vl" dbtype="query">
    	SELECT * FROM getLvs
        WHERE LEAVETYPE = '#VLcode#'
    </cfquery>
    <CFIF vl.RecordCount>
    	<cfset VLpend = vl.COUNT>
    </CFIF>
    
    <cfquery name="ul" dbtype="query">
    	SELECT * FROM getLvs
        WHERE LEAVETYPE = '#ULcode#'
    </cfquery>
    <CFIF ul.RecordCount>
    	<cfset ULpend = ul.COUNT>
    </CFIF>

</CFIF>

<cfset sLVLbegBal = chcNum(sLVLbegBal)>
<cfset sLEarnLv = chcNum(sLEarnLv)>
<cfset sLActLv = chcNum(sLActLv)>
<cfset vLEarnLv = chcNum(vLEarnLv)>
<cfset vLActLv = chcNum(vLActLv)>
<cfset ulbegBal = chcNum(ulbegBal)>
<cfset uLActLv = chcNum(uLActLv)>


<CFSET SLActBal = Evaluate( (sLVLbegBal + sLEarnLv) - sLActLv )>
<CFSET VLActBal  = Evaluate( (sLVLbegBal + vLEarnLv) - vLActLv )>
<CFSET ULActBal = Evaluate( ulbegBal - uLActLv )>

<CFOUTPUT>
<TABLE  BORDER = 1 CELLPADDING = 3 CELLSPACING = 0 class="prelvtble">
	<TR>
    	<TH WIDTH = "150px">&nbsp;</TD>
        <TH WIDTH = "150px">Sick Leave</TD>
        <TH WIDTH = "150px">Vacation Leave</TD>
        <TH WIDTH = "150px">Unscheduled Leave</TD>
    </TR>
    <TR>
    	<TD>Beg. Balance as of <b>Jan #Year(Now())#</b></TD>
        <TD>#sLVLbegBal#</TD>
        <TD>#sLVLbegBal#</TD>
        <TD>#ulbegBal#</TD>
    </TR>
    <TR>
    	<TD>YTD Earned Leaves</TD>
        <TD>#sLEarnLv#</TD>
        <TD>#vLEarnLv#</TD>
        <TD>-</TD>
    </TR>
    <TR>
    	<TD>YTD Used Leaves</TD>
        <TD>#sLActLv#</TD>
        <TD>#vLActLv#</TD>
        <TD>#uLActLv#</TD>
    </TR>
    <TR>
    	<TD>YTD Actual Balance</TD> 
        <TD>#SLActBal#</TD>
        <TD>#VLActBal#</TD>
       <TD>#ULActBal#</TD>
    </TR>
    <TR>
    	<TD>YTD Pending Approval/Unused</TD> 
        <TD>#SLpend#</TD>
        <TD>#VLpend#</TD>
       <TD>#ULpend#</TD>
    </TR>
    <TR>
    	<TD>YTD Available Balance</TD> 
        <TD>#Evaluate(SLActBal - SLpend )#</TD>
        <TD>#Evaluate(VLActBal - VLpend )#</TD>
        <TD>#Evaluate(ULActBal - ULpend )#</TD>
    </TR>     
</TABLE>
</CFOUTPUT>

<cffunction name="chcNum" returntype="numeric" access="private">
	<cfargument name="str" type="string" default="0">
    
    <CFIF Len(str) AND IsNumeric(str)>
    	<cfreturn str>
    <CFELSE>
    	<cfreturn 0>
    </CFIF>
    

</cffunction>



<style type="text/css">
	.prelvtble{
		border-collapse:collapse; 
		border:1px solid ##000
	}
	
	.prelvtble TR TH {
		font-weight:bold;	
		font-size:12px;
	}
	
	.prelvtble tr:not(:first-child) td:not(:first-child){
		text-align:center;
		font-weight:bold;	
	}
</style>

